package models

import (
	"errors"
	"fmt"

	"github.com/gin-gonic/gin"
)

// Comment 评论实体
type Comment struct {
	ID       int    `form:"id"`
	PostId   string `form:"postId"`
	Content  string `form:"content"`
	URL      string `form:"url"`
	UserName string `form:"username"`
	Email    string `form:"email"`
	ParentID int    `form:"parentId"`
	Time     string `form:"time"`
}

func (s *Comment) Bind(ctx *gin.Context) error {
	// log := api.GetRequestLogger(ctx)
	err := ctx.ShouldBindUri(s)
	if err != nil {
		fmt.Println(err.Error())
		return errors.New("数据绑定出错")
	}
	err = ctx.ShouldBind(s)
	if err != nil {
		fmt.Println(err.Error())
		// log.Errorf("ShouldBind error: %s", err.Error())
		err = errors.New("数据绑定出错")
	}
	return err
}

// Comment 获取分页请求实体
type CommentPageReq struct {
	PostId    string `form:"postId"`
	PageNum   int    `form:"pageNum"`
	PageLimit int    `form:"pageLimit"`
}

func (s *CommentPageReq) Bind(ctx *gin.Context) error {
	err := ctx.ShouldBindUri(s)
	if err != nil {
		fmt.Println(err.Error())
		return errors.New("数据绑定出错")
	}
	err = ctx.ShouldBind(s)
	if err != nil {
		fmt.Println(err.Error())
		err = errors.New("数据绑定出错")
	}
	return err
}

// CommentPage 评论分页
type CommentPage struct {
	PrevPage    int       `json:"prevPage"`
	NextPage    int       `json:"nextPage"`
	HasPrevPage bool      `json:"hasPrevPage"`
	HasNextPage bool      `json:"hasNextPage"`
	Rows        []Comment `json:"rows"`
}
